package com.example.bootdemo.common.result;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
public class ResultBody implements Serializable {
    private String code;
    private String message;
    private Object data;
    public ResultBody(ResultCode resultCode, Object data){
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }
    public void setResultCode(ResultCode resultCode){
        this.code = resultCode.code();
        this.message = resultCode.message();
    }

    //操作成功
    public static ResultBody success(){
        ResultBody resultBody = new ResultBody();
        resultBody.setResultCode(ResultCode.SUCCESS);
        return resultBody;
    }
    public static ResultBody success(Object data){
        ResultBody resultBody = new ResultBody();
        resultBody.setResultCode(ResultCode.SUCCESS);
        resultBody.setData(data);
        return resultBody;
    }
    public static ResultBody success(String code, String message, Object data){
        ResultBody resultBody = new ResultBody();
        resultBody.setCode(code);
        resultBody.setMessage(message);
        resultBody.setData(data);
        return resultBody;
    }
    //失败具体要求失败原因
    public static ResultBody failure(ResultCode resultCode){
        ResultBody resultBody = new ResultBody();
        resultBody.setResultCode(resultCode);
        return resultBody;
    }
    public static ResultBody failure(String code, Object data){
        ResultBody resultBody = new ResultBody();
        resultBody.setCode(code);
        resultBody.setData(data);
        return resultBody;
    }
    public static ResultBody failure(ResultCode resultCode, Object data){
        ResultBody resultBody = new ResultBody();
        resultBody.setResultCode(resultCode);
        resultBody.setData(data);
        return resultBody;
    }
    public static ResultBody failure(String code, String message, Object data){
        ResultBody resultBody = new ResultBody();
        resultBody.setCode(code);
        resultBody.setMessage(message);
        resultBody.setData(data);
        return resultBody;
    }

}
